%--------------------------------------------------------------------------
%
% computes a solution to the t = O(1) basic state problem using separation
% of variables and then compares to the numerical solution
%
%--------------------------------------------------------------------------

function v1 = sep_var(fig, p)

if nargin == 0
    fig = 1;
    p = params;
elseif nargin == 1
    p = params;
end
    
s = base(p);

[t, z] = meshgrid(s.x, linspace(0, 1, p.N));


c = 1/6 * p.beta * (1 - p.beta);
phi = c - p.beta * (1 - p.beta) * t;

for n = 1:100
    c = p.beta * (1 - p.beta) * 2 * (-1)^n / n^2 / pi^2;
    phi = phi + c * exp(-n^2 * pi^2 * t) .* cos(n * pi * z);
end

v1 = phi - 1/2 * p.beta * (1 - p.beta) * z.^2;
v1 = p.delta * v1;

v_max = s.y(end-1,:);

if fig
    loglog(s.x, abs(v_max), s.x, abs(v1(end,:)));
    xlabel('t');
    ylabel('|v(h(t),t)|');
end
